```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RabbitMQ延迟队列原理详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .code-block::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 40px;
            background-color: rgba(255,255,255,0.1);
            border-radius: 0.5rem 0.5rem 0 0;
        }
        .code-block .lang-tag {
            position: absolute;
            top: 10px;
            left: 15px;
            color: white;
            font-size: 0.8rem;
            font-family: monospace;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0,0,0,0.1);
        }
        .concept-node {
            transition: all 0.3s ease;
        }
        .concept-node:hover {
            transform: scale(1.05);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">RabbitMQ延迟队列原理</h1>
                    <p class="text-xl opacity-90 mb-8">探索TTL+DLX与延迟插件的实现机制</p>
                    <div class="flex items-center">
                        <span class="bg-white text-purple-700 px-4 py-2 rounded-full font-semibold mr-3">
                            <i class="fas fa-rabbit mr-2"></i>消息队列
                        </span>
                        <span class="bg-white text-purple-700 px-4 py-2 rounded-full font-semibold">
                            <i class="fas fa-clock mr-2"></i>延迟处理
                        </span>
                    </div>
                </div>
                <div class="md:w-1/2">
                    <div class="bg-white bg-opacity-20 p-8 rounded-xl backdrop-blur-sm">
                        <div class="text-center">
                            <i class="fas fa-exchange-alt text-5xl mb-4"></i>
                            <h3 class="text-2xl font-bold mb-2">消息流转机制</h3>
                            <p class="opacity-90">TTL与死信队列协同工作，实现灵活的延迟消息处理</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-6xl px-4 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-purple-600 w-12 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">实现原理概述</h2>
            </div>
            <p class="text-lg text-gray-700 leading-relaxed mb-6">
                RabbitMQ 支持延迟队列的原理可以通过以下两种方式来实现：<span class="font-bold text-purple-600">TTL（Time-to-Live）和死信队列（DLX）组合</span>，以及使用 <span class="font-bold text-purple-600">延迟消息插件</span>。下面将详细解释这两种方式的原理。
            </p>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl p-6 card">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-hourglass-half text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold">TTL+DLX组合</h3>
                    </div>
                    <p class="text-gray-600">通过设置消息的生存时间(TTL)和配置死信交换(DLX)机制实现延迟队列</p>
                </div>
                <div class="bg-white rounded-xl p-6 card">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-plug text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-bold">延迟消息插件</h3>
                    </div>
                    <p class="text-gray-600">使用官方插件直接支持延迟消息功能，无需复杂配置</p>
                </div>
            </div>
        </section>

        <!-- TTL + DLX Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-purple-600 w-12 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">TTL + 死信队列(DLX)实现</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card">
                <div class="p-6">
                    <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                        <i class="fas fa-info-circle text-purple-600 mr-2"></i> 原理概述
                    </h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-purple-700">TTL（Time-to-Live）</h4>
                            <p class="text-gray-600">
                                在 RabbitMQ 中，TTL 是一种机制，用于指定队列或消息的生存时间。TTL 到期后，消息将被删除或转发到死信队列（DLX）。对于消息 TTL，用户可以设置每条消息的存活时间。
                            </p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-lg mb-2 text-purple-700">死信队列（DLX, Dead-Letter Exchange）</h4>
                            <p class="text-gray-600">
                                当消息的 TTL 到期后，消息会被自动转发到绑定了死信交换机的队列（死信队列）。DLX 机制允许将 TTL 过期的消息发送到一个指定的交换机，然后交换机会将消息转发到预定义的队列中。
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-xl font-bold text-gray-800 mb-6 flex items-center">
                    <i class="fas fa-cogs text-purple-600 mr-2"></i> 实现过程
                </h3>
                <div class="grid md:grid-cols-3 gap-6 mb-8">
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-purple-600 text-2xl mb-3">
                            <i class="fas fa-plus-circle"></i>
                        </div>
                        <h4 class="font-bold mb-2">创建TTL队列</h4>
                        <p class="text-gray-600 text-sm">设置消息的TTL参数，决定消息在队列中存活的时间</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-purple-600 text-2xl mb-3">
                            <i class="fas fa-exchange-alt"></i>
                        </div>
                        <h4 class="font-bold mb-2">配置死信交换</h4>
                        <p class="text-gray-600 text-sm">为TTL队列配置死信交换机和目标队列</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-purple-600 text-2xl mb-3">
                            <i class="fas fa-users"></i>
                        </div>
                        <h4 class="font-bold mb-2">消费目标队列</h4>
                        <p class="text-gray-600 text-sm">消息TTL到期后转发到目标队列供消费者使用</p>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-code text-purple-600 mr-2"></i> 配置示例
                </h3>
                <div class="code-block">
                    <span class="lang-tag">bash</span>
                    <pre class="text-gray-300"><code># 1. 创建死信交换机
rabbitmqadmin declare exchange name=dlx_exchange type=direct

# 2. 创建死信队列，并绑定到死信交换机
rabbitmqadmin declare queue name=delayed_queue arguments='{"x-message-ttl":60000,"x-dead-letter-exchange":"dlx_exchange"}'
rabbitmqadmin declare queue name=dlx_queue
rabbitmqadmin declare binding source=dlx_exchange destination=dlx_queue routing_key="delayed_routing_key"

# 3. 发送消息到延迟队列，消息会在 TTL 到期后被转发到死信队列
rabbitmqadmin publish exchange=delayed_exchange routing_key="delayed_routing_key" payload="Delayed Message"</code></pre>
                </div>
            </div>
        </section>

        <!-- Plugin Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-blue-600 w-12 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">延迟消息插件实现</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card">
                <div class="p-6">
                    <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                        <i class="fas fa-info-circle text-blue-600 mr-2"></i> 原理概述
                    </h3>
                    <p class="text-gray-600">
                        RabbitMQ 提供了一个 <span class="font-bold text-blue-600">延迟消息插件</span>，它允许在发送消息时直接指定延迟时间，而不需要使用 TTL 和 DLX 组合。插件支持通过一个特殊的交换机类型 <code class="bg-blue-100 text-blue-800 px-1 rounded">x-delayed-message</code>，并允许用户在消息中设置延迟时间。
                    </p>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-xl font-bold text-gray-800 mb-6 flex items-center">
                    <i class="fas fa-cogs text-blue-600 mr-2"></i> 实现过程
                </h3>
                <div class="grid md:grid-cols-4 gap-6 mb-8">
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-blue-600 text-2xl mb-3">
                            <i class="fas fa-download"></i>
                        </div>
                        <h4 class="font-bold mb-2">安装插件</h4>
                        <p class="text-gray-600 text-sm">安装rabbitmq-delayed-message-exchange插件</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-blue-600 text-2xl mb-3">
                            <i class="fas fa-exchange-alt"></i>
                        </div>
                        <h4 class="font-bold mb-2">定义交换机</h4>
                        <p class="text-gray-600 text-sm">创建x-delayed-message类型的交换机</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-blue-600 text-2xl mb-3">
                            <i class="fas fa-paper-plane"></i>
                        </div>
                        <h4 class="font-bold mb-2">发送消息</h4>
                        <p class="text-gray-600 text-sm">通过消息头设置延迟时间</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm card">
                        <div class="text-blue-600 text-2xl mb-3">
                            <i class="fas fa-route"></i>
                        </div>
                        <h4 class="font-bold mb-2">自动路由</h4>
                        <p class="text-gray-600 text-sm">延迟时间到后消息路由到目标队列</p>
                    </div>
                </div>
            </div>

            <div>
                <h3 class="text-xl font-bold text-gray-800 mb-4 flex items-center">
                    <i class="fas fa-code text-blue-600 mr-2"></i> 配置示例
                </h3>
                <div class="code-block">
                    <span class="lang-tag">bash</span>
                    <pre class="text-gray-300"><code># 1. 创建延迟交换机
rabbitmqadmin declare exchange name=delayed_exchange type=x-delayed-message arguments='{"x-delayed-type":"direct"}'

# 2. 创建队列并绑定到延迟交换机
rabbitmqadmin declare queue name=delayed_queue
rabbitmqadmin declare binding source=delayed_exchange destination=delayed_queue routing_key="delayed_routing_key"

# 3. 发送带有延迟属性的消息
rabbitmqadmin publish exchange=delayed_exchange routing_key="delayed_routing_key" payload="Delayed Message" properties='{"headers":{"x-delay": 60000}}'</code></pre>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-indigo-600 w-12 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">两种实现方式对比</h2>
            </div>
            <div class="bg-white rounded-xl overflow-hidden shadow-md card">
                <div class="p-6">
                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">对比项</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-purple-600 uppercase tracking-wider">TTL+DLX</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-blue-600 uppercase tracking-wider">延迟插件</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">实现复杂度</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中等，需要配置TTL和DLX</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">简单，直接使用插件</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">灵活性</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">每个队列固定TTL</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">每条消息独立设置延迟</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">性能</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">较好</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">略低，因需要排序</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">兼容性</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">原生支持</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">需要安装插件</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-1 bg-teal-600 w-12 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">流程可视化</h2>
            </div>
            <div class="bg-white rounded-xl p-6 shadow-md card">
                <div class="mermaid">
                    graph TD
                        A[生产者] -->|发送消息| B[TTL队列]
                        B -->|TTL到期| C[死信交换机]
                        C --> D[死信队列]
                        D --> E[消费者]
                        
                        F[生产者] -->|发送延迟消息| G[延迟交换机]
                        G -->|延迟到期| H[目标队列]
                        H --> I[消费者]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-4 text-center">
            <div class="mb-6">
                <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                <p class="text-gray-400">探索技术奥秘，分享知识精华</p>
            </div>
            <div class="mb-6">
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition duration-300">
                    <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="flex justify-center space-x-4">
                <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                    <i class="fab fa-github text-xl"></i>
                </a>
                <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                    <i class="fab fa-twitter text-xl"></i>
                </a>
                <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                    <i class="fab fa-linkedin text-xl"></i>
                </a>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 微交互效果
        document.querySelectorAll('.card').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.boxShadow = '0 10px 25px rgba(0,0,0,0.1)';
            });
            card.addEventListener('mouseleave', function() {
                this.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)';
            });
        });
    </script>
</body>
</html>
```